<?php
/************************************************************************
 Omnitrix - PHP Development Framework
 Copyright (C) 2012-2018 amonest(eastson@outlook.com)

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
************************************************************************/

$GLOBALS['_XTEMP'] = array();

function otx_response_content_set($type, $content)
{
	$GLOBALS['_XTEMP'][$type] = $content;
}

function otx_response_content_get($type)
{
	if (!isset($GLOBALS['_XTEMP'][$type])) {
		return null;
	}
	return $GLOBALS['_XTEMP'][$type];
}

function otx_response_content_unset($type)
{
	unset($GLOBALS['_XTEMP'][$type]);
}

function otx_response_content_list($type)
{
	if (!isset($GLOBALS['_XTEMP'][$type])) {
		return null;
	}
	return (array) $GLOBALS['_XTEMP'][$type];
}

function otx_response_content_add($type, $content)
{
	if (!isset($GLOBALS['_XTEMP'][$type])) {
		$GLOBALS['_XTEMP'][$type] = array();
	}

	$GLOBALS['_XTEMP'][$type] = (array) $GLOBALS['_XTEMP'][$type];

	if (func_num_args() >= 3) {
		$GLOBALS['_XTEMP'][$type][func_get_arg(2)] = $content;
	} else {
		$GLOBALS['_XTEMP'][$type][] = $content;
	}
}

function otx_response_content_delete($type, $content)
{
	if (!isset($GLOBALS['_XTEMP'][$type])) {
		return;
	}
	if (!is_array($content) && isset($GLOBALS['_XTEMP'][$type][$content])) {
		unset($GLOBALS['_XTEMP'][$type][$content]);
	} else if (false !== ($key = array_search($content, $GLOBALS['_XTEMP'][$type]))) {
		unset($GLOBALS['_XTEMP'][$type][$key]);
	}
}

function otx_response_title_set($title)
{
	otx_response_content_set('title', $title);
}

function otx_response_title_get()
{
	return otx_response_content_get('title');
}

function otx_response_jscript_list()
{
	return otx_response_content_list('jscript');
}

function otx_response_jscript_reset()
{
	return otx_response_content_reset('jscript');
}

function otx_response_jscript_add($jscript, $file = true)
{
	otx_response_content_add('jscript', array(
	'file' => $file,
	'jscript' => $jscript
	));
}

function otx_response_jscript_delete($jscript, $file = true)
{
	otx_response_content_delete('jscript', array(
	'file' => $file,
	'jscript' => $jscript
	));
}

function otx_response_jstext_list()
{
	return otx_response_content_list('jstext');
}

function otx_response_jstext_reset()
{
	return otx_response_content_reset('jstext');
}

function otx_response_jstext_add($key, $tex)
{
	otx_response_content_add('jstext', $text, $key);
}

function otx_response_jstext_delete($key)
{
	otx_response_content_delete('jstext', $key);
}

function otx_response_style_list()
{
	return otx_response_content_list('style');
}

function otx_response_style_reset()
{
	return otx_response_content_reset('style');
}

function otx_response_style_add($style, $file = true)
{
	otx_response_content_add('style', array(
		'file' => $file,
		'style' => $style
	));
}

function otx_response_style_delete($style, $file = true)
{
	otx_response_content_delete('style', array(
		'file' => $file,
		'style' => $style
	));
}

function otx_response_body_list()
{
	return otx_response_content_list('body');
}

function otx_response_body_reset()
{
	return otx_response_content_reset('body');
}

function otx_response_body_add($body)
{
	otx_response_content_add('body', $body);
}

function otx_response_body_delete($body)
{
	otx_response_content_delete('body', $body);
}